export function isString(v?: string): boolean {
    return Object.prototype.toString.call(v) === "[object String]"
}
export function isNumber(v?: number): boolean {
    return Object.prototype.toString.call(v) === "[object Number]"
}
export function isBoolean(v?: boolean): boolean {
    return Object.prototype.toString.call(v) === "[object Boolean]"
}
export function isArray(v?: Array<any>): boolean {
    return Object.prototype.toString.call(v) === "[object Array]"
}
export function isObject(v?: object): boolean {
    return Object.prototype.toString.call(v) === "[object Object]"
}
export function isNill(v: any): boolean {
    return [null, undefined].includes(v)
}
export function isArrayString(v: Array<string>): boolean {
    if (Object.prototype.toString.call(v) !== "[object Array]") return false
    for (let i = 0; i < v.length; i++) {
        const val = v[i]
        if (!isString(val)) return false
        if (val === "") return false
    }
    return true
}
export function isArrayNumber(v: Array<number>): boolean {
    if (Object.prototype.toString.call(v) !== "[object Array]") return false
    for (let i = 0; i < v.length; i++) {
        const val = v[i]
        if (!isNumber(val)) return false
    }
    return true
}
//是否是包含小数点后2位的价格
export function isPrice(v: number | string): boolean {
    const REGEXP_PRICE = /^\d{0,8}\.{0,1}(\d{1,2})?$/
    return REGEXP_PRICE.test(v.toString())
}
//是否是整数
export function isInt(v: number | string) {
    const REGEXP_INT = /^\d+$/;
    return REGEXP_INT.test(v.toString())
}

// 两个字符串数组取差值
export function arrayAminusB(arrA: string[], arrB: string[]) {
    return arrA.filter(v => !arrB.includes(v));
}

// 判断两个数组是否相等
export function isArrayEquals(array1: Array<string | number | boolean>, array2: Array<string | number | boolean>) {
    return array1.length == array2.length && isArrayIncludes(array1, array2)
}

// 判断数组A是否包含数组B的值
export function isArrayIncludes(array1: Array<string | number | boolean>, array2: Array<string | number | boolean>) {
    return array2.every((v, i) => { return array1.includes(v) });
}
// 删除对象属性并返回
export function omit(object: Record<string, unknown>, props: string[]): Record<string, unknown> {
    let obj: Record<string, unknown> = {}
    Object.keys(object).forEach(item => {
        if (!props.includes(item)) {
            obj[item] = object[item]
        }
    })
    return obj
}
// 创建一个从 object 中选中的属性的对象
export function pick(object: Record<string, unknown>, props: string[]): Record<string, unknown> {
    let obj: Record<string, unknown> = {}
    Object.keys(object).forEach(item => {
        if (props.includes(item)) {
            obj[item] = object[item]
        }
    })
    return obj
}

// 清除格式
export function clearFormat(str: string) {
    return str.replace(/\s+/g, "").replace(/<\/?.+?>/g, "").replace(/[\r\n]/g, "")
}

